package cn.changeforyou.web.cloud.gateway.filter;

import cn.changeforyou.base.model.ResultInfo;
import cn.changeforyou.web.cloud.gateway.utils.WebFluxUtils;
import org.springframework.http.server.reactive.ServerHttpResponse;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.netty.ByteBufFlux;

public class BaseFilter {

    /**
     * 响应异常信息
     * @param response
     * @param resultInfo
     * @return
     */
    protected Mono<Void> reponseErrorInfo(ServerHttpResponse response, ResultInfo resultInfo) {
        return response.writeAndFlushWith(Flux.just(ByteBufFlux.just(response.bufferFactory().wrap(WebFluxUtils.getWrapData(resultInfo)))));
    }
}
